Skip to content

Comments

Lint unused features#152164

Open
mu001999 wants to merge 5 commits intorust-lang:mainfrom
mu001999-contrib:lint/unused_features
Open

Lint unused features#152164
mu001999 wants to merge 5 commits intorust-lang:mainfrom
mu001999-contrib:lint/unused_features

Conversation

@mu001999
Copy link
Contributor

@mu001999 mu001999 commented Feb 5, 2026

View all comments

Fixes #44232
Fixes #151752


This PR records used features through query side effect, then reports unsued features finally.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 5, 2026
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is neat! in the future, it would be easier to review if you split the rename into a separate commit from the change in behavior.

could you add some tests for this please?

View changes since this review

@mu001999 mu001999 force-pushed the lint/unused_features branch 2 times, most recently from cb9b84c to cd83e12 Compare February 5, 2026 15:31
@mu001999
Copy link
Contributor Author

mu001999 commented Feb 5, 2026

Initial implementation completed. I plan to add more tests and check whether features in rustc are reported as unused correctly or not.

@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from cd83e12 to 2945856 Compare February 6, 2026 00:38
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 2945856 to 36c0a20 Compare February 6, 2026 01:00
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 36c0a20 to 2ddaf82 Compare February 7, 2026 01:16
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 2ddaf82 to fb08c95 Compare February 7, 2026 11:37
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from fb08c95 to 38aefe4 Compare February 7, 2026 12:45
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 38aefe4 to 0cda8d4 Compare February 7, 2026 13:35
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 0cda8d4 to 2d2577f Compare February 7, 2026 14:19
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 2d2577f to b67632e Compare February 7, 2026 15:08
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch 2 times, most recently from a940d65 to 435090a Compare February 8, 2026 02:11
@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 20, 2026
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 20, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 20, 2026

☀️ Try build successful (CI)
Build commit: c5f63cc (c5f63ccbcca9aa53fca1ca26b806737efa5cf682, parent: 59fd4ef94daa991e6797b5aa6127e824f3067def)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c5f63cc): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.6% [0.1%, 1.1%] 158
Regressions ❌
(secondary)
0.6% [0.1%, 1.9%] 155
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.7%, -0.1%] 3
All ❌✅ (primary) 0.6% [0.1%, 1.1%] 158

Max RSS (memory usage)

Results (primary 0.1%, secondary 1.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.2% [1.9%, 2.5%] 2
Regressions ❌
(secondary)
3.0% [1.2%, 4.8%] 3
Improvements ✅
(primary)
-1.9% [-3.3%, -0.6%] 2
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 1
All ❌✅ (primary) 0.1% [-3.3%, 2.5%] 4

Cycles

Results (primary 1.6%, secondary -0.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.1% [2.2%, 4.7%] 3
Regressions ❌
(secondary)
2.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
-2.7% [-2.7%, -2.7%] 1
Improvements ✅
(secondary)
-3.1% [-3.1%, -3.1%] 1
All ❌✅ (primary) 1.6% [-2.7%, 4.7%] 4

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 481.762s -> 483.482s (0.36%)
Artifact size: 397.93 MiB -> 398.06 MiB (0.03%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 20, 2026
@JonathanBrouwer
Copy link
Contributor

Perf is a lot better now but it's still quite a regression, I wonder what we can do to fix the last bit of perf loss

@bjorn3
Copy link
Member

bjorn3 commented Feb 20, 2026

Maybe we could skip this new code when unstable features are not allowed at all (not nightly and no RUSTC_BOOTSTRAP)?

@mu001999 mu001999 force-pushed the lint/unused_features branch 4 times, most recently from b015168 to bc3edee Compare February 21, 2026 00:40
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is great!

Do you have an idea where the remaining perf regression comes from?

View changes since this review

pub mir_opt_bisect_eval_count: AtomicUsize,

pub used_features: Lock<Option<Arc<WorkerLocal<RefCell<FxHashMap<Symbol, Option<u32>>>>>>>,
used_features_weak: Weak<WorkerLocal<RefCell<FxHashMap<Symbol, Option<u32>>>>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I have in mind. So we avoid encoding several DepNodes for each feature. Even with that we already have up to 3% increase in dep-graph size!

@mu001999 mu001999 force-pushed the lint/unused_features branch from bc3edee to 2d2add7 Compare February 21, 2026 01:13
@mu001999
Copy link
Contributor Author

mu001999 commented Feb 21, 2026

Do you have an idea where the remaining perf regression comes from?

I think it might be related to the overhead caused by query side effects and recording used features themselves. After all, we added an extra table and still need to traverse all enabled features during the final reporting phase.

Anyway, I think we could do another perf run first because the new impl is simper than before.

@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 2d2add7 to a283871 Compare February 21, 2026 02:16
@mu001999
Copy link
Contributor Author

@JonathanBrouwer Please help do the perf run again, thanks!

@JonathanBrouwer
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 21, 2026

⌛ Trying commit a283871 with merge eca2935

To cancel the try build, run the command @bors try cancel.

Workflow: https://github.com/rust-lang/rust/actions/runs/22254092757

rust-bors bot pushed a commit that referenced this pull request Feb 21, 2026
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) perf-regression Performance regression. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-perf Status: Waiting on a perf run to be completed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustc could warn if a feature is unused Re-enable detection of unused library #![feature] directives

9 participants